﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _0912089
{
    public class ImageView : SingleView
    {
        public ImageView(string strTexture, Vector2 pos, float scale)
        {
            _background = GameBase.Constant.content.Load<Texture2D>(strTexture);
            Position = pos;
            _scale = scale;
            _size = new Vector2(_background.Width, _background.Height);            
        }

        public ImageView(string strTexture, Vector2 pos, Vector2 size)
        {
            _background = GameBase.Constant.content.Load<Texture2D>(strTexture);
            Position = pos;
            _size = size;
        }

        public ImageView(Texture2D texture, Vector2 pos, Vector2 sizeOfImageView)
        {
            _background = texture;
            Position = pos;

            float scaleX = sizeOfImageView.X / texture.Width;
            float scaleY = sizeOfImageView.Y / texture.Height;
            float minScale = (scaleX < scaleY) ? scaleX : scaleY;

            _size = minScale * new Vector2(texture.Width, texture.Height);

            if (_size.X < _size.Y)
            {
                Position = new Vector2(Position.X + Math.Abs(sizeOfImageView.X - _size.X) / 2, Position.Y);
            }
            if (_size.X > _size.Y)
            {
                Position = new Vector2(Position.X, Position.Y + Math.Abs(sizeOfImageView.Y - _size.Y) / 2);
            }
        }

        public override void draw(GameTime gameTime, SpriteBatch spriteBatch, Color color)
        {
            if (Visible && Background != null)
                spriteBatch.Draw(Background, new Rectangle((int)Position.X, (int)Position.Y, (int)(Scale * Size.X), (int)(Scale * Size.Y)), ColorForDraw * Alpha);
        }

    }
}
